@echo off
setlocal

rem To use this script, you need:
rem  * Visual Studio 2008 installed
rem  * SVN and grep (somewhere in %PATH%)

rem some config
set shared_files=HISTORY.txt LICENSE.txt
set miranda_files=translation.txt translation-russian.txt
set qip_files=
set additional_label=_alpha

rem set configuration folder
set configuration=Release Unicode
if "%1"=="" goto cont
if %1==debug set configuration=Debug Unicode
:cont

rem make sure that we have the last revision
svn up

rem rebuild
call "%vs90comntools%vsvars32.bat"
msbuild /m /t:Rebuild "/p:Configuration=%configuration%" /v:d fileasmsg.sln
if errorlevel 1 goto :eof

rem obtaint version
for /f "usebackq tokens=5,6 delims=_	" %%I in (`grep "#define _FILEASMSG_PLUGIN_VERSION_" plugin.h`) do set %%I=%%J
for /f "usebackq tokens=3" %%I in (`grep SVN_REV svnrev.h`) do set REVISION=%%I

rem compress miranda plugin
move "%configuration%\FileAsMsg_miranda\FileAsMsg.dll" .
del FileAsMsg_miranda_%LEADING%_%HIGH%_%LOW%_%REVISION%%additional_label%.zip 2>nul
7za a -tzip FileAsMsg_miranda_%LEADING%_%HIGH%_%LOW%_%REVISION%%additional_label%.zip FileAsMsg.dll %shared_files% %miranda_files%
move FileAsMsg.dll "%configuration%\FileAsMsg_miranda"

rem compress qip plugin
set destdir="%configuration%\FileAsMsg_qip\FileAsMsg"
mkdir %destdir%
call :copy_all %shared_files% %qip_files%
cd %destdir%\..
move FileAsMsg.dll FileAsMsg
del ..\..\FileAsMsg_qip_%LEADING%_%HIGH%_%LOW%_%REVISION%%additional_label%.zip 2>nul
7za a -tzip ..\..\FileAsMsg_qip_%LEADING%_%HIGH%_%LOW%_%REVISION%%additional_label%.zip FileAsMsg
move FileAsMsg\FileAsMsg.dll .
del /q FileAsMsg\*.*
rmdir FileAsMsg
cd ..\..
endlocal
goto :eof

:copy_all
if "%1"=="" goto :eof
copy %1 %destdir%
shift
goto copy_all
